package com.cmy.mvvm.test.ui

import android.annotation.SuppressLint
import android.os.Looper
import com.cmy.framework.mvvm.mvvm.model.IModel
import com.cmy.framework_network.TecentNetworkWithoutEnvelopeApi
import com.cmy.framework_utils.log.KLog
import com.cmy.mvvm.test.api.Api
import com.cmy.mvvm.test.api.NewsChannelsBean
import com.cmy.mvvm.test.api.NewsListBean

/**
 * @name:
 *  HomeModel
 * @package:
 *  com.cmy.mvvm.test
 * @date:
 *  2023/2/1708:48
 * @author
 *    cmy
 * @description
 *
 */
class HomeModel : IModel() {


    /**
     * 获取新闻列表
     */
    suspend fun getNewsList(channelId: String?, channelName: String?, page: String?,
                             onSuccess:(NewsListBean)->Unit,
                             onFailure:(String?)->Unit){
        val newsListBean = TecentNetworkWithoutEnvelopeApi.getService(Api::class.java).getNewsList(channelId,channelName,page.toString())
        networkResponse(newsListBean,onSuccess,onFailure)

    }


    @SuppressLint("SuspiciousIndentation")
    suspend fun getNewsChannels(onSuccess:(NewsChannelsBean)->Unit,
                                onFailure:(String?)->Unit){
      val  newsChannelsBean = TecentNetworkWithoutEnvelopeApi.getService(Api::class.java).getNewsChannelsWithoutEnvelope()
        KLog.i("Looper",if(Looper.getMainLooper() == Looper.myLooper()) "1主线程pre" else "1子线程pre")
        networkResponse(newsChannelsBean,onSuccess,onFailure)
    }


}